package com.ruoyi.web.controller.website;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.MaterialCourse;
import com.ruoyi.module.service.IMaterialCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程内容Controller
 *
 * @author fubojin
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/website/materialCourse")
public class WebMaterialCourseController extends BaseController
{
    @Autowired
    private IMaterialCourseService materialCourseService;

    /**
     * 查询课程内容列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MaterialCourse materialCourse)
    {
        startPage();
        List<MaterialCourse> list = materialCourseService.selectMaterialCourseList(materialCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程内容列表
     */
    @Log(title = "课程内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialCourse materialCourse)
    {
        List<MaterialCourse> list = materialCourseService.selectMaterialCourseList(materialCourse);
        ExcelUtil<MaterialCourse> util = new ExcelUtil<MaterialCourse>(MaterialCourse.class);
        util.exportExcel(response, list, "课程内容数据");
    }

    /**
     * 获取课程内容详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id, @RequestParam Long userId)
    {
        return success(materialCourseService.selectMaterialCourseById(id, userId));
    }

    /**
     * 新增课程内容
     */
    @Log(title = "课程内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialCourse materialCourse)
    {
        return toAjax(materialCourseService.insertMaterialCourse(materialCourse));
    }

    /**
     * 修改课程内容
     */
    @Log(title = "课程内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialCourse materialCourse)
    {
        return toAjax(materialCourseService.updateMaterialCourse(materialCourse));
    }

    /**
     * 删除课程内容
     */
    @Log(title = "课程内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialCourseService.deleteMaterialCourseByIds(ids));
    }
}
